/**
 * Description:
 * Class Name:Client
 * Date:2022/5/23 16:25
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第17章_网络编程._17_3_基于TCP协议的网络编程._17_3_3_使用Socket进行通信;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        String targetIP = "localhost";
        int targetPort = 30000;
        var socket = new Socket(targetIP, targetPort);
        // 将Socket对应的输入流包装成BufferReader
        var br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        // 进行普通的IO操作
        String line = br.readLine();
        System.out.println("来自服务器的数据：" + line);
        // 关闭输入流，关闭socket
        br.close();
        socket.close();
    }
}
